<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title>新增用户</title>
    <script th:replace="common/head::static"></script>
</head>
<body>
<form class="layui-form" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否超管</label>
        <div class="layui-input-inline">
            <select name="isSuper">
                <option value="N" th:selected="true">否</option>
                <option value="Y">是</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-inline">
            <select name="sysDeptId">
                <option th:value="${sysDept.id}" th:text="${sysDept.name}" th:each="sysDept,iterStat : ${sysDepts}">-</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否可用</label>
        <div class="layui-input-inline">
            <select name="valid">
                <option value="Y" th:selected="true">是</option>
                <option value="N">否</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sysUserSave">确认</button>
            <button type="button" class="layui-btn layui-btn-primary" id="sysUserSaveCancel">取消</button>
        </div>
    </div>
</form>
<script th:src="@{/common/js/common.js}"></script>
<script>
    layui.use(['form'], function () {
        const $ = layui.jquery,
            layer = layui.layer,
            form = layui.form;
        form.render();

        form.on('submit(sysUserSave)', function (obj) {
            obj.field.sysDept = {id: obj.field.sysDeptId};
            Common.ajaxPostJSON(ctx + "/sysUser/save", JSON.stringify(obj.field), function (res){
                if (res.value === 200) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        parent.$('#sysUserSearchBtn').click();
                        Common.closeFrame();
                    });
                } else {
                    layer.msg(res.message, {icon: 2, time: 2000});
                }
            })
            return false;
        });

        $("#sysUserSaveCancel").on('click', function () {
            Common.closeFrame();
        });
    });
</script>
</body>
</html>